Adding Dynamic Types 您所在的位置:网站首页 Adding Static Content MIME Mappings Adding Dynamic Types

Adding Dynamic Types

2024-07-07 09:03| 来源: 网络整理| 查看: 265

Adding Dynamic Types Article 04/06/2022

Overview

The element of the element adds a unique MIME type to the list of types that IIS 7 will compress dynamically.

Note

Unlike the IIS 6.0 HcScriptFileExtensions metabase property that defined specific file name extensions as "dynamic content," IIS 7 uses the element to specify which MIME types IIS 7 will compress dynamically, and it uses mappings in the element to specify which file name extensions refer to static or dynamic content.

Compatibility Version Notes IIS 10.0 The element was not modified in IIS 10.0. IIS 8.5 The element was not modified in IIS 8.5. IIS 8.0 The element was not modified in IIS 8.0. IIS 7.5 The element was not modified in IIS 7.5. IIS 7.0 The element of the element was introduced in IIS 7.0. IIS 6.0 The element is somewhat analogous to the IIS 6.0 HcScriptFileExtensions metabase property.

Setup

HTTP compression is usually available on the default installation of IIS 7 and later. However, only static compression is installed by default. To install static or dynamic compression, use the following steps.

Windows Server 2012 or Windows Server 2012 R2 On the taskbar, click Server Manager. In Server Manager, click the Manage menu, and then click Add Roles and Features. In the Add Roles and Features wizard, click Next. Select the installation type and click Next. Select the destination server and click Next. On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Performance, and then select Static Content Compression and/or Dynamic Content Compression. Click Next. . On the Select features page, click Next. On the Confirm installation selections page, click Install. On the Results page, click Close. Windows 8 or Windows 8.1 On the Start screen, move the pointer all the way to the lower left corner, right-click the Start button, and then click Control Panel. In Control Panel, click Programs and Features, and then click Turn Windows features on or off. Expand Internet Information Services, expand World Wide Web Services, expand Performance Features, and then select Dynamic Content Compression and/or Static Content Compression. Click OK. Click Close. Windows Server 2008 or Windows Server 2008 R2 On the taskbar, click Start, point to Administrative Tools, and then click Server Manager. In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS). In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services. On the Select Role Services page of the Add Role Services Wizard, select Dynamic Content Compression if you want to install dynamic compression and Static Content Compression if you want to install static compression, and then click Next. On the Confirm Installation Selections page, click Install. On the Results page, click Close. Windows Vista or Windows 7 On the taskbar, click Start, and then click Control Panel. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off. Expand Internet Information Services, then World Wide Web Services, then Performance Features. Select Http Compression Dynamic if you want to install dynamic compression and Static Content Compression if you want to install static compression. Click OK.

How To

There is no user interface for setting the dynamic content types for IIS 7. For examples of how to set the dynamic content types programmatically, see the Code Samples section of this document.

Configuration Attributes Element Description enabled Required Boolean attribute.

Specifies whether a new MIME type can use dynamic compression.

The default value is true.

mimeType Required string attribute.

Specifies the name of the MIME type, also called the content type, that uses dynamic compression.

Child Elements

None.

Configuration Sample

The following default element is configured in the ApplicationHost.config file in IIS 7. This configuration section inherits the default configuration settings unless you use the element.

Sample Code

The following code samples will add the MIME types for Office 2003 documents to the list of dynamic compression types.

(> [!NOTE]

Office 2007 documents use built-in compression, so they do not need to be compressed by IIS.)

AppCmd.exe appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/msword',enabled='True']" /commit:apphost appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/vnd.ms-powerpoint',enabled='True']" /commit:apphost appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/vnd.ms-excel',enabled='True']" /commit:apphost

Note

You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

C# using System; using System.Text; using Microsoft.Web.Administration; internal static class Sample { private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection httpCompressionSection = config.GetSection("system.webServer/httpCompression"); ConfigurationElementCollection dynamicTypesCollection = httpCompressionSection.GetCollection("dynamicTypes"); ConfigurationElement addElement = dynamicTypesCollection.CreateElement("add"); addElement["mimeType"] = @"application/msword"; addElement["enabled"] = true; dynamicTypesCollection.Add(addElement); ConfigurationElement addElement1 = dynamicTypesCollection.CreateElement("add"); addElement1["mimeType"] = @"application/vnd.ms-powerpoint"; addElement1["enabled"] = true; dynamicTypesCollection.Add(addElement1); ConfigurationElement addElement2 = dynamicTypesCollection.CreateElement("add"); addElement2["mimeType"] = @"application/vnd.ms-excel"; addElement2["enabled"] = true; dynamicTypesCollection.Add(addElement2); serverManager.CommitChanges(); } } } VB.NET Imports System Imports System.Text Imports Microsoft.Web.Administration Module Sample Sub Main() Dim serverManager As ServerManager = New ServerManager Dim config As Configuration = serverManager.GetApplicationHostConfiguration Dim httpCompressionSection As ConfigurationSection = config.GetSection("system.webServer/httpCompression") Dim dynamicTypesCollection As ConfigurationElementCollection = httpCompressionSection.GetCollection("dynamicTypes") Dim addElement As ConfigurationElement = dynamicTypesCollection.CreateElement("add") addElement("mimeType") = "application/msword" addElement("enabled") = True dynamicTypesCollection.Add(addElement) Dim addElement1 As ConfigurationElement = dynamicTypesCollection.CreateElement("add") addElement1("mimeType") = "application/vnd.ms-powerpoint" addElement1("enabled") = True dynamicTypesCollection.Add(addElement1) Dim addElement2 As ConfigurationElement = dynamicTypesCollection.CreateElement("add") addElement2("mimeType") = "application/vnd.ms-excel" addElement2("enabled") = True dynamicTypesCollection.Add(addElement2) serverManager.CommitChanges() End Sub End Module JavaScript var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager'); adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"; var httpCompressionSection = adminManager.GetAdminSection("system.webServer/httpCompression", "MACHINE/WEBROOT/APPHOST"); var dynamicTypesCollection = httpCompressionSection.ChildElements.Item("dynamicTypes").Collection; var addElement = dynamicTypesCollection.CreateNewElement("add"); addElement.Properties.Item("mimeType").Value = "application/msword"; addElement.Properties.Item("enabled").Value = true; dynamicTypesCollection.AddElement(addElement); var addElement1 = dynamicTypesCollection.CreateNewElement("add"); addElement1.Properties.Item("mimeType").Value = "application/vnd.ms-powerpoint"; addElement1.Properties.Item("enabled").Value = true; dynamicTypesCollection.AddElement(addElement1); var addElement2 = dynamicTypesCollection.CreateNewElement("add"); addElement2.Properties.Item("mimeType").Value = "application/vnd.ms-excel"; addElement2.Properties.Item("enabled").Value = true; dynamicTypesCollection.AddElement(addElement2); adminManager.CommitChanges(); VBScript Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager") adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST" Set httpCompressionSection = adminManager.GetAdminSection("system.webServer/httpCompression", "MACHINE/WEBROOT/APPHOST") Set dynamicTypesCollection = httpCompressionSection.ChildElements.Item("dynamicTypes").Collection Set addElement = dynamicTypesCollection.CreateNewElement("add") addElement.Properties.Item("mimeType").Value = "application/msword" addElement.Properties.Item("enabled").Value = True dynamicTypesCollection.AddElement(addElement) Set addElement1 = dynamicTypesCollection.CreateNewElement("add") addElement1.Properties.Item("mimeType").Value = "application/vnd.ms-powerpoint" addElement1.Properties.Item("enabled").Value = True dynamicTypesCollection.AddElement(addElement1) Set addElement2 = dynamicTypesCollection.CreateNewElement("add") addElement2.Properties.Item("mimeType").Value = "application/vnd.ms-excel" addElement2.Properties.Item("enabled").Value = True dynamicTypesCollection.AddElement(addElement2) adminManager.CommitChanges()


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有